﻿using MyUAMS.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyUAMS.BLL
{
    public class CategoryServer
    {
        DataClasses1DataContext db = new DataClasses1DataContext();
        public AssetType_Table GetCategoryById(int tid)
        {
            return (from c in db.AssetType_Table
                    where c.Tid == tid
                    select c).First();
        }
        public void InsertCategory(int tid, string tname, string tdescribe)
        {
            AssetType_Table category = new AssetType_Table();
            category.Tid = tid;
            category.Tname = tname;
            category.TDescribe = tdescribe;

            db.AssetType_Table.InsertOnSubmit(category);
            db.SubmitChanges();
        }
        public void UpdateCategory(int tid, string tname, string tdescribe)
        {
            AssetType_Table category = (from c in db.AssetType_Table
                                        where c.Tid == tid
                                        select c).First();
            category.Tname = tname;
            category.TDescribe = tdescribe;

            db.SubmitChanges();
        }
        public void DeleteCategory(int tid)
        {
            AssetType_Table category = (from c in db.AssetType_Table
                                        where c.Tid == tid
                                        select c).First();
            db.AssetType_Table.DeleteOnSubmit(category);
            db.SubmitChanges();
        }
        public List<AssetType_Table> GetAllCategory()
        {
            return (from c in db.AssetType_Table
                    select c).ToList();
        }
        public int GetProductCountByCategoryId(int categoryId)
        {
            return (from p in db.Asset_Table
                    where p.Tid == categoryId
                    select p).Count();
        }
    }
}
